
/**********************************************************************
  * @file:        xxx.c
  * @author:      guangjieMVP
  * @version:     v1.00.00
  * @date:        2020-xx-xx
  * @github:      https://github.com/guangjieMVP
  * @brief: 
************************************************************************/
#include "stack_with_range_check.h"
#include "string.h"

static int __check(stack_validator_t *s,int val)
{
    if(!s)
        return -1;

    stack_range_check_t *tmp = (stack_range_check_t *)s;
    if(val >= tmp->min && val < tmp->max)
    {
        return 0;
    }
    return -1;
}

/**********************************************************************
  * @brief:         初始化范围校验器    
  * @param[in]:     None
  * @retval[out]:   None
  * @note:          初始化范围校验器    
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
stack_validator_t *stack_wtih_range_check_init(stack_range_check_t *s, int max, int min)
{
    if(!s)     //参数检查
        return -1;
    
    stack_validator_init(&s->super, __check);      //初始化基类校验器
    s->max  = max;
    s->min  = min;
    return &s->super;                              //返回一个基类校验器
}

/**********************************************************************
  * @brief:         解初始化对象(析构函数)
  * @param[in]:     None
  * @retval[out]:   None
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
int stack_with_range_check_deinit(stack_range_check_t *s)
{
    if(!s)
        return -1;

    s->min = 0;
    s->min = 0;
    return stack_validator_deinit(&s->super);     //再解初始化父类成员
}